package view;

import java.rmi.RemoteException;

import javax.swing.JFrame;
import javax.swing.JRadioButton;


import server.FirewallSession;

import server.FirewallException;
import server.NotExpertException;
import server.ReadWriteException;

public class RulesetSaveFrame extends AbstractTextFieldFrame
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 8132796840501212792L;
	public FirewallSession UI;
	
	/* For saving as current ruleset */
	JRadioButton current = null;
	
	/**
	 * C'tor
	 * Define the frame
	 */
	public RulesetSaveFrame(FirewallSession ui)
	{
	    super("Ruleset", "Enter the name for copy of current running ruleset:");
	    UI = ui;
	    textFiled.setText(Settings.ruleset);	    	
	}

	/**
	 * Action performed by finish button press:
	 * save the relevant ruleset from two tables 
	 */
	protected void finishAction()
	{
		Settings.ruleset = textFiled.getText();
		try {
			UI.createRuleSet(Settings.ruleset);
		} catch (RemoteException e) {
			ErrorFrame.AddError("Failed to duplicate current running ruleset:" + e.getMessage(), new JFrame());
		} catch (FirewallException e) {
			ErrorFrame.AddError("Failed to duplicate current running ruleset:" + e.getMessage(), new JFrame());
		} catch (ReadWriteException e) {
			ErrorFrame.AddError("Failed to duplicate current running ruleset:" + e.getMessage(), new JFrame());
		} catch (NotExpertException e) {
			ErrorFrame.AddError("Failed to duplicate current running ruleset:" + e.getMessage(), new JFrame());
		}	
		
		RulesAdvancedFrame.currentRulesAdvancedFrame.isCurrentRuleSet(false);
		RulesAdvancedTable.currentInRulesAdvancedTable.build();
		RulesAdvancedTable.currentOutRulesAdvancedTable.build();
		
		dispose();
	}
}
